package com.mayuan.controller;

import com.mayuan.domain.ResponseResult;
import com.mayuan.domain.dto.AddArticleDto;
import com.mayuan.domain.dto.ArticleListDto;
import com.mayuan.domain.entity.Article;
import com.mayuan.domain.vo.ArticleInfoVo;
import com.mayuan.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @PostMapping
    public ResponseResult add(@RequestBody AddArticleDto articleDto){
        return articleService.add(articleDto);
    }

    @GetMapping("/list")
    public ResponseResult list(Integer pageNum, Integer pageSize, ArticleListDto articleListDto){
        return articleService.pageArticleList(pageNum,pageSize,articleListDto);
    }

    @GetMapping("/{id}")
    public ResponseResult getArticleInfo(@PathVariable("id") Long id){
        return articleService.getArticleInfo(id);
    }

    @PutMapping
    public ResponseResult updateArticle(@RequestBody ArticleInfoVo articleInfoVo){
        return articleService.updateArticle(articleInfoVo);
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteById(@PathVariable("id") Long id){
        return articleService.deleteById(id);
    }

}
